package com.ctg.behavior.utils;

import java.math.BigDecimal;
import java.math.RoundingMode;

import org.apache.commons.lang3.StringUtils;

public class CtDoubleUtils {

	public static Double percent2Scale(String double1, String double2) {
		if (StringUtils.isEmpty(double1) || StringUtils.isEmpty(double2)) {
			return 0.00D;
		}
		Double vDouble1 = Double.valueOf(double1) * 100;
		Double vDouble2 = Double.valueOf(double2);
		if (vDouble2 <= 0) {
			return 0.00D;
		}
		Double formatDouble = CtDoubleUtils.format2Scale(vDouble1 / vDouble2);
		return formatDouble;
	}

	public static Double sum2Scale(String double1, String double2) {
		if (StringUtils.isEmpty(double1) || StringUtils.isEmpty(double2)) {
			return 0.00D;
		}
		Double sumDouble = Double.valueOf(double1) + Double.valueOf(double2);
		Double formatDouble = CtDoubleUtils.format2Scale(sumDouble);
		return formatDouble;
	}

	public static String percent2Scale(Long numerator, Long denominator) {
		if (denominator <= 0) {
			return "0.00";
		}
		Double percent = CtDoubleUtils.percent2Scale(Double.valueOf(numerator), Double.valueOf(denominator));
		return percent.toString();
	}

	public static Double percent2Scale(Double numerator, Double denominator) {
		if (denominator <= 0) {
			return 0.0D;
		}
		numerator = numerator * 100;
		Double percent = CtDoubleUtils.format2Scale(numerator / denominator);
		return percent;
	}

	public static Double format2Scale(Double value) {
		BigDecimal bg = new BigDecimal(value);
		Double f2value = bg.setScale(2, RoundingMode.UP).doubleValue();
		return f2value;
	}

}
